package main

import (
	"fmt"
)

func solution(dna1 string, dna2 string) int {
	m := len(dna1)
	n := len(dna2)
	// 初始化一个 (m+1) x (n+1) 的二维数组 dp
	dp := make([][]int, m+1)
	for i := range dp {
		dp[i] = make([]int, n+1)
	}

	// 初始化边界条件
	for i := 0; i <= m; i++ {
		dp[i][0] = i
	}
	for j := 0; j <= n; j++ {
		dp[0][j] = j
	}

	// 填充 dp 数组
	for i := 1; i <= m; i++ {
		for j := 1; j <= n; j++ {
			if dna1[i-1] == dna2[j-1] {
				dp[i][j] = dp[i-1][j-1]
			} else {
				dp[i][j] = min(min(dp[i-1][j], dp[i][j-1]), dp[i-1][j-1]) + 1
			}
		}
	}

	return dp[m][n]
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	fmt.Println(solution("AGCTTAGC", "AGCTAGCT") == 2)
	fmt.Println(solution("AGCCGAGC", "GCTAGCT") == 4)
}
